using System;
using System.Runtime.InteropServices;

namespace Leap
{
	public class Bone : Interface
	{
		public enum BoneType
		{
			TYPE_METACARPAL,
			TYPE_PROXIMAL,
			TYPE_INTERMEDIATE,
			TYPE_DISTAL
		}

		private HandleRef swigCPtr;

		public Vector PrevJoint
		{
			get
			{
				IntPtr intPtr = LeapPINVOKE.Bone_PrevJoint_get(swigCPtr);
				return (intPtr == IntPtr.Zero) ? null : new Vector(intPtr, true);
			}
		}

		public Vector NextJoint
		{
			get
			{
				IntPtr intPtr = LeapPINVOKE.Bone_NextJoint_get(swigCPtr);
				return (intPtr == IntPtr.Zero) ? null : new Vector(intPtr, true);
			}
		}

		public Vector Center
		{
			get
			{
				IntPtr intPtr = LeapPINVOKE.Bone_Center_get(swigCPtr);
				return (intPtr == IntPtr.Zero) ? null : new Vector(intPtr, true);
			}
		}

		public Vector Direction
		{
			get
			{
				IntPtr intPtr = LeapPINVOKE.Bone_Direction_get(swigCPtr);
				return (intPtr == IntPtr.Zero) ? null : new Vector(intPtr, true);
			}
		}

		public float Length => LeapPINVOKE.Bone_Length_get(swigCPtr);

		public float Width => LeapPINVOKE.Bone_Width_get(swigCPtr);

		public BoneType Type => (BoneType)LeapPINVOKE.Bone_Type_get(swigCPtr);

		public Matrix Basis
		{
			get
			{
				IntPtr intPtr = LeapPINVOKE.Bone_Basis_get(swigCPtr);
				return (intPtr == IntPtr.Zero) ? null : new Matrix(intPtr, true);
			}
		}

		public bool IsValid => LeapPINVOKE.Bone_IsValid_get(swigCPtr);

		public static Bone Invalid => new Bone(LeapPINVOKE.Bone_Invalid_get(), false);

		public Bone(IntPtr cPtr, bool cMemoryOwn)
			: base(LeapPINVOKE.Bone_SWIGUpcast(cPtr), cMemoryOwn)
		{
			swigCPtr = new HandleRef(this, cPtr);
		}

		public static HandleRef getCPtr(Bone obj)
		{
			return obj?.swigCPtr ?? new HandleRef(null, IntPtr.Zero);
		}

		~Bone()
		{
			Dispose();
		}

		public override void Dispose()
		{
			lock (this)
			{
				if (swigCPtr.Handle != IntPtr.Zero)
				{
					if (base.swigCMemOwn)
					{
						base.swigCMemOwn = false;
						LeapPINVOKE.delete_Bone(swigCPtr);
					}
					swigCPtr = new HandleRef(null, IntPtr.Zero);
				}
				GC.SuppressFinalize(this);
				base.Dispose();
			}
		}

		public Bone()
			: this(LeapPINVOKE.new_Bone(), true)
		{
		}

		public bool Equals(Bone arg0)
		{
			bool result = LeapPINVOKE.Bone_Equals(swigCPtr, getCPtr(arg0));
			if (LeapPINVOKE.SWIGPendingException.Pending)
			{
				throw LeapPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public override string ToString()
		{
			return LeapPINVOKE.Bone_ToString(swigCPtr);
		}
	}
}
